package windowFactoryPackage;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

public class DeveloperProgramWindow extends WindowGenerator {
	static ArrayList<JPanel> panelList = new ArrayList<JPanel>();
	static ArrayList<JPanel> jtaPanelList = new ArrayList<JPanel>();
	static ArrayList<JPanel> buttonPanelList = new ArrayList<JPanel>();
	static ArrayList<JTextArea> jtaList = new ArrayList<JTextArea>();
	static ArrayList<JButton> viewInfoList = new ArrayList<JButton>();
	static JLabel[] northPanelLabelArray;
	static String[] developerInfo = { "__Dev Name__", "__Dev Web__","__Dev Phone__" };
	private String[] developerLabels = { "Developer Name: ","Developer Website: ", "Developer Phone: " };
	private JPanel northPanel, centerPanel;
	private JScrollPane jspCenter;
	Font f = new Font("Dialog", Font.BOLD + Font.ITALIC, 14);

	public DeveloperProgramWindow() {
		setLayout(new BorderLayout());

		// Set components into northPanel that holds general developer info --
		// see northPanel from InformationWindow
		northPanel = new JPanel();
		northPanel.setLayout(new GridLayout(1, 6));
		northPanelLabelArray = new JLabel[6];
		for (int i = 0; i < 6; i++) {
			if (i % 2 == 0) {
				northPanelLabelArray[i] = new JLabel(developerLabels[i / 2]);
				northPanelLabelArray[i].setFont(f);
			} else {
				northPanelLabelArray[i] = new JLabel(developerInfo[(i - 1) / 2]);
			}
			northPanel.add(northPanelLabelArray[i]);
		}

		add(northPanel, BorderLayout.NORTH);

		// Initialize variable size ArrayLists and set them onto centerPanel
		// centerPanel set onto JScrollPane and added to parent frame
		for (int i = 0; i < jtaList.size(); i++) {
			panelList.add(new JPanel(new BorderLayout()));
			jtaPanelList.add(new JPanel(new GridLayout(1, 1)));
			
			jtaList.get(i).setEditable(false);
			
			buttonPanelList.add(new JPanel(new GridLayout(1, 2, 20, 20)));
			buttonPanelList.get(i).setBackground(Color.WHITE);
			
			viewInfoList.add(new JButton("View Program"));
			viewInfoList.get(i).addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					for (int i = 0; i < viewInfoList.size(); i++) {
						if (e.getSource() == viewInfoList.get(i)) {
							System.out.println("ViewInfoButton pressed at " + i);
							SearchWindow.setSearch(Query.devProgName.get(i), "p");
							dispose();
						}
					}
				}
			});
			
			jtaPanelList.get(i).add(jtaList.get(i));
			
			buttonPanelList.get(i).add(viewInfoList.get(i));
			
			panelList.get(i).add(jtaPanelList.get(i), BorderLayout.CENTER);
			panelList.get(i).add(buttonPanelList.get(i), BorderLayout.EAST);
		}
		if(panelList.size()>5){
			centerPanel = new JPanel(new GridLayout(panelList.size(), 2, 20, 20));
		} else {
			centerPanel = new JPanel(new GridLayout(6,2,20,20));
		}
		centerPanel.setBackground(Color.WHITE);

		for (int i = 0; i < panelList.size(); i++) {
			centerPanel.add(panelList.get(i));
		}

		jspCenter = new JScrollPane(centerPanel);
		jspCenter.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		jspCenter.getVerticalScrollBar().setUnitIncrement(16);

		add(jspCenter, BorderLayout.CENTER);
	}
}
